﻿#include <Sys\RenderUnit\SysRenderDatagram\TESTRD.HPP>
#include <Render\Render_Win32\Render_Win32_OpenGL\RENDER_WIN32_OPENGL.HPP>
#include <Sys\RenderUnit\SYSDDCLASSID.HPP>


using namespace CxxlMan;
using namespace Cxxl3D;

class CTestDDOpenGL:public IDatagramDisposal_OpenGL
{
  virtual bool cxxlFASTCALL Exec(const Smart_Ptr<IRenderDatagramDisposalCenterOpengl> &IRenderDatagramDisposalCenter_Arg,
    const Smart_Ptr<IRenderDatagram> &IRenderDatagram_Arg, const CxxlMan::CSmart_Ptr<Matrix4x4> &ViewMatrix_Arg)
  {
    Smart_Ptr<ITestRD> ITestRD_Ptr = (ITestRD*)GetDefaultInterface(IRenderDatagram_Arg);
    Smart_Ptr<IC3D_Node> IC3D_Node_Ptr = ITestRD_Ptr->Get_IC3D_Node();
    CSmart_Ptr<const Matrix4x4> WorldMatrix_Ptr = IC3D_Node_Ptr->GetWorldMatrix();

    Matrix4x4 WorldViewMatrix = (*WorldMatrix_Ptr) * (*ViewMatrix_Arg);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf((C3D_FLOAT*)(Matrix4x4*)&WorldViewMatrix); // Set Modeview matrix


    glDisable(GL_LIGHTING);
    glDisable(GL_CULL_FACE);

    unsigned int Count; 
    Vector4 *pVector4;

    ITestRD_Ptr->GetData(&Count, &pVector4);

  	// `畫出金字塔的8條邊線`
	  glEnableClientState(GL_VERTEX_ARRAY);
	  glVertexPointer(4, GL_FLOAT, sizeof(Vector4), pVector4);
	  glDrawArrays(GL_LINES, 0, Count * 2);

    return true;
  }

public:
  // Consteructor
  CTestDDOpenGL()
    :cxxlObject(Spirit_Easy)
  {
  }

  // Desteructor
  virtual ~CTestDDOpenGL()
  {
  }

};

cxxlObject *cxxlFASTCALL New_CTestDDOpenGL()
{
  return new CTestDDOpenGL;
}